import axios from 'axios'

const rootUrl = '/files'

// import {MAX_LENGTH} from 'api/config'

// 筛选相应的路径下的图片
export function getPictures (path, token) {
  return axios({
    'method': 'GET',
    url: rootUrl,
    'headers': {
      'authorization': `Bearer ${token}\n`
    },
    'processData': false,
    'contentType': false,
    'mimeType': 'multipart/form-data',
    params: {
      having: {
        'prefix': path
      }
    }
    // params: {
    //   max: MAX_LENGTH,
    //   dir: `${dir}/`,
    //   nextKey
    // }
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

export function delPicture (key, token) {
  return axios({
    'method': 'DELETE',
    url: `${rootUrl}/${key}`,
    'headers': {
      'Authorization': `Bearer ${token}\n`
    }
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
